<template class="view">
  <div>
    <OperateC
        :top-level="topLevel"
        :add="addQuartz"
        :edit="editQuartz"
        :remove="removeQuartz"
        :add-show="this.$getButtonAuth('job:add')"
        :remove-show="this.$getButtonAuth('job:del:batch')"
    />
    <QuartzTable
        :top-level="topLevel"
        :edit-show="this.$getButtonAuth('job:edit')"
        :del-show="this.$getButtonAuth('job:del')"
        :pause-show="this.$getButtonAuth('job:pause')"
        :run-show="this.$getButtonAuth('job:run')"
        :once-show="this.$getButtonAuth('job:once')"
    />
    <QuartzDialog></QuartzDialog>
  </div>
</template>

<script>
import QuartzDialog from "@/components/dialog/QuartzDialog";
import OperateC from "@/components/OperateC";
import QuartzTable from "@/components/table/QuartzTable";
import {deleteQuartzByIds, getQuartzs} from "@/api/quartz";
export default {
  name: "QuartzView",
  components: {QuartzDialog, OperateC, QuartzTable},
  data() {
    return {
      topLevel: -1
    }
  },
  methods: {
    addQuartz() {
      let params = {
        dialogFormVisible: true,
        dialogTitle: "添加定时任务"
      }
      this.$store.commit("quartz/openDialogForm", params);
    },
    editQuartz() {
      let selected = this.$store.state.quartz.multipleSelection;
      if (selected.length < 1) {
        this.$message.warning("你还没有选中数据哦！");
        return;
      }
      if (selected.length > 1) {
        this.$message.warning("一次只能修改一条数据哦！")
        return;
      }
      this.$store.dispatch("quartz/editQuartz", selected[0]);
    },
    removeQuartz() {
      let selected = this.$store.state.quartz.multipleSelection;
      if (selected.length < 1) {
        this.$message.warning("请先选择要删除的数据哦！");
        return;
      }
      this.$confirm('确定删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteQuartzByIds(selected).then((res) => {
          this.$message.success(res.data.msg);
          // 刷新
          let params = {
            "current": this.$store.state.quartz.currentPage,
            "size": this.$store.state.quartz.pageSize
          };
          getQuartzs(params).then((res) => {
            this.$store.state.quartz.tableData = res.data.data;
            this.$store.state.quartz.total = res.data.total;
          })
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
  }
}
</script>

<style scoped>

</style>
